package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.myapplication.Adapter.ListViewAdapter;
import com.example.myapplication.Model.ListViewModel;

import java.util.ArrayList;
import java.util.List;

public class ListViewActivity extends AppCompatActivity {

    private List<ListViewModel> data = new ArrayList<>();
    private ListView mListView;
    private String TAG = "ListViewActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);

        for (int i = 0; i < 30; i++) {
            ListViewModel model = new ListViewModel();
            model.setName("test" + i);
            data.add(model);
        }

        mListView = findViewById(R.id.lv);
        mListView.setAdapter(new ListViewAdapter(data, this));
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(ListViewActivity.this, "item: "+position, Toast.LENGTH_SHORT).show();
            }
        });
        Log.e(TAG, "ListView");
    }
}